﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using XNET.IO;

namespace 文件看门狗
{
    public partial class FormDog : Form
    {
        public FormDog()
        {
            InitializeComponent();
        }

        private void btnEncrypt_Click(object sender, EventArgs e)
        {
            string inFile = txtFileName.Text;
            string outFile = inFile + ".dat";
            string password = txtPassword.Text;
            XFileEncrypt.EncryptFile(inFile, outFile, password);//加密文件
            //删除加密前的文件
            File.Delete(inFile);
            txtFileName.Text = string.Empty;
            MessageBox.Show("加密成功");
        }

        private void btnDeencrypt_Click(object sender, EventArgs e)
        {
            string inFile = txtFileName.Text;
            string outFile = inFile.Substring(0, inFile.Length - 4);
            string password = txtPassword.Text;
            XFileEncrypt.DecryptFile(inFile, outFile, password);//解密文件
            //删除解密前的文件
            File.Delete(inFile);
            txtFileName.Text = string.Empty;
            MessageBox.Show("解密成功");
        }

        private void btnOpen_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                txtFileName.Text = openFileDialog1.FileName;
            }
        }
    }
}
